import 'package:flutter/material.dart';

class SampleCustomScrollView extends StatefulWidget {
  const SampleCustomScrollView({Key? key}) : super(key: key);

  @override
  _SampleCustomScrollViewState createState() => _SampleCustomScrollViewState();
}

class _SampleCustomScrollViewState extends State<SampleCustomScrollView> {
  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: [
        renderTitle('SliverGrid'),
        SliverGrid.count(
          crossAxisCount: 3,
          children: Colors.primaries
              .map((e) => Container(
                    color: e,
                  ))
              .toList(),
        ),
        renderTitle('SliverList'),
        SliverFixedExtentList(
          delegate: SliverChildBuilderDelegate((context, index) {
            return Container(
              color: Colors.primaries[index],
            );
          }, childCount: Colors.primaries.length),
          itemExtent: 100,
        )
      ],
    );
  }

  Widget renderTitle(String s) {
    return SliverToBoxAdapter(
      child: Padding(
        padding: EdgeInsets.symmetric(vertical: 16),
        child: Text(
          s,
          textAlign: TextAlign.center,
          style: TextStyle(fontSize: 20),
        ),
      ),
    );
  }
}
